﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public enum enumErrorNo
{
    Fail = -1
    , Success = 0, WrongFormat, WrongArgument, WrongOperation
    , ErrorNotExist=100, ErrorExist, ErrorNotEmpty, ErrorEmptyOrNull, ErrorNotSame, ErrorSame, ErrorNotChange, ErrorChange
    , ErrorCreate = 200, ErrorRead, ErrorUpdate, ErrorDelete, ErrorOpen, ErrorClose, ErrorWrite, ErrorLock
}

namespace FormBaseLib
{
    public class CBase
    {
        // 2014-07-14, Honda, for copyto....related
        public CBase mBase { get { return this; } }

        public int miLastError { get; private set; }
        public string msLastError { get; private set; }
        public bool mbLastError { get { return miLastError!=0;} }

        public CBase()
        {
            ClearLastError();
        }
        public void ClearLastError()
        {
            SetLastError(enumErrorNo.Success, string.Empty);
        }
        public void SetLastError(string sError)
        {
            SetLastError(enumErrorNo.Fail, string.Empty);
        }

        public void SetLastError(int iError, string sError)
        {
            miLastError = iError;
            msLastError = sError;
        }
        public void SetLastError(enumErrorNo pError, string sError)
        {
            SetLastError((int)pError, sError);
        }
        public override string ToString()
        {
            return string.Format("{0},{1}", miLastError, msLastError);
        }
        // 2014-07-14, Honda, bad pratice in a base class implement in C#.
        //public void CopyTo(CLastError pTo)
        //{
        //    pTo.SetLastError(miLastError, msLastError);
        //}
        public void SetBase(CBase pFrom)
        {
            SetLastError(pFrom.miLastError, pFrom.msLastError);
        }
        public void SetLastError(CBase pFrom)
        {
            SetLastError(pFrom.miLastError, pFrom.msLastError);
        }
    }
}
